package kevin.hbase.bean;

import cc.chinagps.gateway.buff.GBossDataBuff;
import kevin.hbase.constant.Constant;
import kevin.hbase.util.DateTimeUtil;
import lombok.Data;

import java.util.List;

@Data
public class HbaseGps {
    private String callLetter;
    private String gpsTimeStr;
    private long gpsTime;
    private String receiveTime;
    double longitude;
    double latitude;
    int speed;
    List<Integer> statusList;
    int locationType;
    private int gwId;
    private Integer electricity;
    private String source;

    public static HbaseGps valueOf(GBossDataBuff.GpsBaseInfo baseinfo) {
        HbaseGps gps = new HbaseGps();
        gps.setGpsTime(baseinfo.getGpsTime());
        gps.setGpsTimeStr(DateTimeUtil.getDateTimeGMT8AsString(baseinfo.getGpsTime(), Constant.DATETIMEFORMAT));
        gps.setReceiveTime(DateTimeUtil.getDateTimeGMT8AsString(baseinfo.getReceiveTime(), Constant.DATETIMEFORMAT));
        int locationType = baseinfo.getLocationType();
        if (locationType == 1 || locationType == 9) {
            gps.setLatitude(Double.valueOf(baseinfo.getLat()) / 1000000);
            gps.setLongitude(Double.valueOf(baseinfo.getLng()) / 1000000);
        } else {
            if (baseinfo.hasAddress()) {
                gps.setLatitude(Double.valueOf(baseinfo.getAddress().getLat()) / 1000000);
                gps.setLongitude(Double.valueOf(baseinfo.getAddress().getLng()) / 1000000);
            }
        }
        gps.setSpeed(baseinfo.getSpeed());
        gps.setStatusList(baseinfo.getStatusList());
        gps.setLocationType(locationType);

        if (baseinfo.hasBeijingInfo()) {
            GBossDataBuff.BeiJingInfo beijingInfo = baseinfo.getBeijingInfo();
            if (beijingInfo.hasElectricity()) {
                gps.setElectricity(beijingInfo.getElectricity());
            }
        }
        return gps;
    }
}
